package com.repu.dyz.controller;

import com.github.pagehelper.PageInfo;
import com.repu.dyz.entity.SysUser;
import com.repu.dyz.service.UserService;
import com.repu.dyz.utils.DataResult;
import com.repu.dyz.vo.req.LoginReqVO;
import com.repu.dyz.vo.req.UserPageReqVO;
import com.repu.dyz.vo.resp.LoginRespVO;
import com.repu.dyz.vo.resp.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @ClassNameUserController
 * @Description
 * @Author: daiyizheng
 * @Date2020/12/10 8:55 下午
 * @Version V1.0
 **/
@RestController
@RequestMapping("/api")
@Api(tags = "用户模块相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户登录接口")
    @PostMapping("/user/login")
    public DataResult<LoginRespVO> login(@RequestBody @Valid LoginReqVO vo){
        DataResult result=DataResult.success();
        result.setData(userService.login(vo));
        return result;
    }

//自定义分页层
//    @PostMapping("/users")
//    @ApiOperation(value = "分页查询用户接口")
//    public DataResult<PageInfo<SysUser>> pageInfo(@RequestBody UserPageReqVO vo){
//        DataResult result=DataResult.success();
//        result.setData(userService.pageInfo(vo));
//        return result;
//    }

    @PostMapping("/users")
    @ApiOperation(value = "分页查询用户接口")
    @RequiresPermissions("sys:user:list")
    public DataResult<PageVO<SysUser>> pageInfo(@RequestBody UserPageReqVO vo){
        DataResult result=DataResult.success();
        result.setData(userService.pageInfo(vo));
        return result;
    }
}
